# NIC Makefile
EXPORT_SYMBOL := true

SYS_TIME=$(shell date +%Y-%m-%d_%H:%M:%S)
EXTRA_CFLAGS += -D __TIME_STR__=\"$(SYS_TIME)\"
GLOBAL_VERSION=$(shell cat $(PWD)/GLOBAL_VERSION_NEW | grep driver | awk -F ':' '{print $$2}')
EXTRA_CFLAGS += -DGLOBAL_VERSION_STR=\"$(GLOBAL_VERSION)\"

$(warning cflags, $(EXTRA_CFLAGS))
V ?= 0

ifeq ($(HI1823_RELEASE_TYPE), LLT)
	EXTRA_CFLAGS += -D_LLT_TEST_
else
	EXTRA_CFLAGS += -DHW_CONVERT_ENDIAN
endif

KVER=$(shell uname -r)
KDIR  := /lib/modules/$(KVER)/build

TAGET_KMOD_NAME ?= hinic3

#sdk
EXTRA_CFLAGS += -I$(PWD)/hw
EXTRA_CFLAGS += -I$(PWD)/hw/include
EXTRA_CFLAGS += -I$(PWD)/hw/kcompat/include
EXTRA_CFLAGS += -I$(PWD)/hw/kcompat/linux/kernel

#nic
EXTRA_CFLAGS += -I$(PWD)
EXTRA_CFLAGS += -I$(PWD)/advance

EXTRA_CFLAGS += -D_SUPPORT_VERSION_
EXTRA_CFLAGS += -DCONFIG_SP_VID_DID
EXTRA_CFLAGS += -D__LINUX__ -Wall
EXTRA_CFLAGS +=-Wno-date-time

ifeq ($(HI1823_OS_TYPE), Ubuntu)
EXTRA_CFLAGS += -g
endif
EXTRA_CFLAGS += -Werror

ifeq ($(HI1823_OS_RELEASE), KylinV10)
else ifeq ($(HI1823_OS_RELEASE), KylinV10SP1)
else ifeq ($(HI1823_OS_RELEASE), KylinV10SP2)
else
EXTRA_CFLAGS += -fstack-protector
endif

obj-m += $(TAGET_KMOD_NAME).o

$(TAGET_KMOD_NAME)-objs := hinic3_dbg.o \
			hinic3_dcb.o \
			hinic3_ethtool.o \
			hinic3_ethtool_stats.o \
			hinic3_filter.o \
			hinic3_ipsec.o \
			hinic3_irq.o \
			hinic3_main.o \
			hinic3_netdev_ops.o \
			hinic3_nic_prof.o \
			hinic3_ntuple.o \
			hinic3_rss.o \
			hinic3_rx.o \
			hinic3_tx.o \
			advance/hinic3_bond.o \
			advance/hinic3_mag_cfg.o \
			advance/hinic3_nic_cfg.o \
			advance/hinic3_nic_cfg_vf.o \
			advance/hinic3_nic_dbg.o \
			advance/hinic3_nic_event.o \
			advance/hinic3_nic_io.o \
			advance/hinic3_rss_cfg.o \
			advance/hisec_cfg.o \
			hw/hinic3_hwdev.o \
			hw/hinic3_hw_cfg.o \
			hw/hinic3_hw_comm.o \
			hw/hinic3_prof_adap.o \
			hw/hinic3_sriov.o \
			hw/hinic3_lld.o \
			hw/hinic3_dev_mgmt.o \
			hw/hinic3_common.o \
			hw/hinic3_hwif.o \
			hw/hinic3_wq.o \
			hw/hinic3_cmdq.o \
			hw/hinic3_eqs.o \
			hw/hinic3_mbox.o \
			hw/hinic3_mgmt.o \
			hw/hinic3_api_cmd.o \
			hw/hinic3_hw_api.o \
			hw/hinic3_sml_lt.o \
			hw/hinic3_hw_mt.o \
			hw/hinic3_nictool.o \
			hw/hinic3_devlink.o \
			hw/hinic3_micro_log.o \
			hw/cqm_bat_cla.o \
			hw/cqm_bitmap_table.o \
			hw/cqm_object_intern.o \
			hw/cqm_bloomfilter.o \
			hw/cqm_cmd.o \
			hw/cqm_db.o \
			hw/cqm_object.o \
			hw/cqm_main.o \
			hw/kcompat/linux/kernel/ossl_knl_linux.o \

default:
	$(MAKE) -C $(KDIR) M=$(PWD) modules

clean:
	@rm -rf .tmp_versions
	@find . -name "*.ko" -exec rm -rf  {} \;
	@find . -name "*.o" -exec rm -rf  {} \;
	@find . -name "*.o.*" -exec rm -rf  {} \;
	@find . -name "*.order" -exec rm -rf  {} \;
	@find . -name "Module.symvers" -exec rm -rf  {} \;
	@find . -name "*.mod.*" -exec rm -rf  {} \;
	@find . -name "*.cmd" -exec rm -rf  {} \;